import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const Login = () => import(/* webpackChunkName: 'login' */ '@/views/login/index')
const dashboard = () => import(/* webpackChunkName: 'dashboard' */ '@/views/dashboard/index')
const Layout = () => import(/* webpackChunkName: 'Layout' */ '../layout/index.vue')

export const constantRoutes = [
  {
    path: '/login',
    name: 'login',
    component: Login,
  },

  {
    path: '/',
    redirect: '/dashboard',
    name: 'layout',
    component: Layout,
    children: [{
      path: '/dashboard',
      name: 'Dashboard',
      component: dashboard,
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
